'use strict';
const db = uniCloud.database()
const dbCmd = db.command
exports.main = async (event, context) => {
	const {authorId,userId} = event
	
	const user = await db.collection('user').doc(userId).get()
	const authorLikeIds = user.data[0].author_likes_ids
	let msg = ''
	
	let author_ids = null
	if(authorLikeIds.includes(authorId)){
		msg = '取消关注'
		author_ids = dbCmd.pull(authorId)
		
	} else{
		msg = '关注成功'
		author_ids = dbCmd.unshift(authorId)
	}

	await  db.collection('user').doc(userId).update({
		// 向其位置插入或删除
		author_likes_ids:author_ids
	})
	//event为客户端上传的参数
	
	
	//返回数据给客户端
	return {
		code:200,
		data:{
			msg
		}
	}
};
